import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

import {
	RECEIVE_ADDRESS,
	RECEIVE_CATEGORYS,
	RECEIVE_SHOPS	
} from './mutation-types.js'

export default new Vuex.Store({
	// Vuex最核心管理的对象
  state: {
		
  },
	// 直接更新state的多个方法对象
  mutations: {
		
		[RECEIVE_ADDRESS] (state, {address}) {
			state.address = address
		},
		
		[RECEIVE_CATEGORYS] (state, {categorys}) {
			state.categorys = categorys
		},
		
		[RECEIVE_SHOPS] (state, {shops}) {
			state.shops = shops
		}
		
		
  },
	// 通过mutations间接更新
  actions: {
		// // 异步获取地址
		// async getAddress({commit, state}) {
		// 	const geohash = state.latitude + ',' + state.longitude
		// 	const { data : res} = await	this.$http.get(`/position/${geohash}`)
		// 	if(res.code !== 0 ) {
		// 		return console.log('获取地址失败！')
		// 	}
		// 	console.log(res)
		// 	const address = res.data.name
		// 	commit(RECEIVE_ADDRESS, {address})
		// },
		// // 异步获取食品分类列表
		// async getCategorys({commit}) {
		// 	const { data : res} = await	this.$http.get('/index_category')
		// 	if(res.code !== 0 ) {
		// 		return console.log('获取食品分类列表失败！')
		// 	}
		// 	console.log(res)
		// 	const categorys = res.data
		// 	commit(RECEIVE_CATEGORYS, {categorys})
		// },
		// // 异步获取商家列表
		// async getShops({commit, state}) {
		// 	const { data : res} = await	this.$http.get('/shops', {params: {
		// 		latitude: state.latitude,
		// 		longitude: state.longitude
		// 	}})
		// 	if(res.code !== 0 ) {
		// 		return console.log('获取商家列表失败！')
		// 	}
		// 	console.log(res)
		// 	const shops = res.data
		// 	commit(RECEIVE_SHOPS, {shops})
		// }
  },
  modules: {
  },
	// 包含多个基于state的getter计算属性对象
	getters: {
		
	}
})
